from rest_framework.response import Response
from rest_framework.views import APIView

from .models import User, News
from .ser import NewsSer


class UserAPIView(APIView):
    def get(self, request):
        name = request.data.get('name')
        password = request.data.get('password')
        user = User.objects.filter(name=name).first()
        pd = User.objects.filter(password=password).first()
        if name == user:
            if pd == password:
                return Response({'code': 200, 'msg': '登录成功'})


class NewsAPIView(APIView):
    def get(self, request):
        user = News.objects.all()
        ser = NewsSer(user, many=True)
        return Response(ser.data)
